package iedcyt.acute.controller.listener.jcrUpdate;

import java.util.HashMap;

import iedcyt.acute.businessServices.ViewLogger;
import iedcyt.acute.controller.listeners.menu.MenuCommonListener;
import iedcyt.acute.model.MenuModel;
import iedcyt.acute.view.MainMenu;
import iedcyt.acute.view.ViewUtils;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;

public class CalculateJCRIndicatorsListener extends MenuCommonListener implements SelectionListener {

	
	/**
	 * @param _model
	 * @param _view
	 */
	public CalculateJCRIndicatorsListener(MenuModel _model, MainMenu _view) {
		super(_model, _view);
		
	}
@Override
	public void widgetDefaultSelected(SelectionEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void widgetSelected(SelectionEvent arg0) {
		String maesorgPath = ViewUtils.getInstance().fileDialog("Base de datos Maesorg", "Seleccione la BD MAESORG con la tabla JCRSCI-SSCIUpdater", "*.mdb");
		
		if (!maesorgPath.isEmpty()) {
			
			HashMap<String,String> beansDb = new HashMap<String,String>();
			beansDb.put("maesorgDataSource", getPath("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=", maesorgPath));
			if (_model.changeDatabases(beansDb)){
				_model.calculateJcrIndicators();
			}else{
				ViewLogger.getInstance().error("No se han podido cambiar las rutas de las bases de datos");
			}
				
		}

	}


	
}
